
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};


function getTime(time) {
    var da = new Date(time).getTime();
    return new Date(da).format("yyyy-MM-dd hh:mm:ss");
}


function getDateTime(time) {
    var da = new Date(time).getTime();
    return new Date(da).format("yyyy-MM-dd hh:mm");
}

function getDate(time) {
    return new Date(time).format("yyyy-MM-dd");
}

function toTimestamp(time) {
    var date = new Date(time.replace(/-/g, '/'));
    return new Date(date).getTime();
}

function sectotime(s) {
    var t;
    if (s > -1) {
        var hour = Math.floor(s / 3600);
        var min = Math.floor(s / 60) % 60;
        if (hour < 10) {
            t = '0' + hour + ":";
        } else {
            t = hour + ":";
        }

        if (min < 10) {
            t += "0";
        }
        t += min;
    }
    return t;
}


function second(time) {
    var s = '';
    var hour = time.split(':')[0];
    var min = time.split(':')[1];
    s = Number(hour * 3600) + Number(min * 60);
    return s;
}

function sectotimesec(time) {
    var secondTime = parseInt(time);// 秒
    var minuteTime = 0;// 分
    var hourTime = 0;// 小时
    if(secondTime > 60) {//如果秒数大于60，将秒数转换成整数
        //获取分钟，除以60取整数，得到整数分钟
        minuteTime = parseInt(secondTime / 60);
        //获取秒数，秒数取佘，得到整数秒数
        secondTime = parseInt(secondTime % 60);
        //如果分钟大于60，将分钟转换成小时
        if(minuteTime > 60) {
            //获取小时，获取分钟除以60，得到整数小时
            hourTime = parseInt(minuteTime / 60);
            //获取小时后取佘的分，获取分钟除以60取佘的分
            minuteTime = parseInt(minuteTime % 60);
        }
    }
    var result = "" + parseInt(secondTime) + "秒";

    if(minuteTime > 0) {
        result = "" + parseInt(minuteTime) + "分" + result;
    }
    if(hourTime > 0) {
        result = "" + parseInt(hourTime) + "小时" + result;
    }
    return result;
}

export  default {
    getTime: getTime,
    getDate: getDate,
    getDateTime: getDateTime,
    toTimestamp: toTimestamp,
    second:second,
    sectotime: sectotime,
    sectotimesec:sectotimesec
}